var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        refund_index:0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

        var id = options.id;
        let that = this;
        let d = app.globalData;
        this.setData({
            platform:d.platform,    
            id:id,
            width:d.windowWidth,
            height:d.windowHeight,
            statusBarHeight:d.statusBarHeight,
            navHeight:d.navHeight,
            navWidth:d.navWidth,
            navRight:d.navRight,
            marginTop:d.navTitleTop,
            domain:d.domain,
            uploadUrl:d.uploadUrl,
          })
    },
    goBack(){
        wx.navigateBack();
    },
    goIndex(){
        var  url ='/pages/customer/index';
        console.log(url);
        wx.reLaunch({
          url:url
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getIndex();
    },
    refundChange(e){
        console.log(e);
        var index = e.detail.value;
        this.setData({
          refund_index:index
        })
      },
    getIndex(){
        var d = this.data;
        let that = this;
        var open =  wx.getStorageSync('open');
        var data = [];
        data['user_id'] = open.user_id;
        data['id'] = d.id;
 
        var url = 'customer/getRefundSelect';

      app.request(url,data,'get').then(res=>{ 
        console.log('---customer ----lose to reject'); 
         console.log(res);
         that.setData({
             customer:res.customer,
             refund:res.refund
         })
         //app.showModals(res.msg,res.url,res.index);
         //that.getIndex();
      });
    },
    onSubmit(e){
        wx.showModal({
          title: '',
          content: '您确定要退订么',
          cancelText:'考虑一下',
          confirmText:'确定退订',
          complete: (res) => {
            if (res.cancel) {
                console.log('---cancle--');
                wx.navigateBack();
            }
        
            if (res.confirm) {
                console.log(`数据：${JSON.stringify(e.detail.value)}`)
        let that = this;
        console.log(e);
        var data= this.data;
        var value = e.detail.value;
       // value.inDate = this.data.inDate;
        var open = wx.getStorageSync('open');
        if(value.refund == 0){
          
            //console.log(stock_index);
            app.showModals('请选择退订类型','#','#')
            return false;
          }

          if(value.desc.length==0){
            app.showModals('请录入本次跟进内容','#','#')
            return false;
          }      
   
          var id = this.data.id;
    
          wx.request({
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
            data: {
              user_id:open.user_id,
              id:id,             
              refund:value.refund,
              desc:value.desc
            
            },
            //method: 'POST',
            dataType: 'json',
            timeout: 30000,
            url: app.globalData.platUrl + 'customer/toRefund',
            success:res=>{
                //console.log(res);
                let data = res.data;
                if(res.statusCode == 200){
                    if(data.status==200){
                        app.showModals('退订成功','list?status=1','#')
                    }else{
                        app.showModals('退订失败','list?status=2','#')
                    }
                }else{
                    app.showModals('服务器错误','#','#')
                }
                
            }
          })
            }
          }
        })
      
       },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})